/**
 * 
 */
package org.log4jconfig.xml.editor.contentassist.attribute;

import java.util.List;

import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.IPackageFragmentRoot;
import org.eclipse.jdt.launching.JavaRuntime;
import org.eclipse.jdt.ui.ISharedImages;
import org.eclipse.wst.xml.ui.internal.contentassist.ContentAssistRequest;
import org.log4jconfig.xml.editor.utils.JdtUtils;

/**
 * @author Xi
 * 
 */
@SuppressWarnings("restriction")
public class LoggerOrCategoryNameContentAssistComputer extends AbstractContentAssistComputer {

	public void addAttributeValueProposals(IJavaProject javaProject, ContentAssistRequest contentAssistRequest,
			String attributeCurrentValue, String attributeMatchValue) throws Exception {
		IPackageFragmentRoot[] packageFragmentRoots = javaProject.getAllPackageFragmentRoots();
		JavaRuntime.computeDefaultRuntimeClassPath(javaProject);
		String matchingPackage = JdtUtils.getPackageFromQualifiedName(attributeCurrentValue);
		List<String> packages = JdtUtils.getPackagesFromFragmentRoots(packageFragmentRoots);
		List<String> classes = JdtUtils.getClassesFromFragmentRoots(packageFragmentRoots, matchingPackage);

		for (String p : packages) {
			addCompletionProposal(contentAssistRequest, p, attributeCurrentValue, attributeMatchValue,
					ISharedImages.IMG_OBJS_PACKAGE);
		}
		for (String c : classes) {
			addCompletionProposal(contentAssistRequest, c, attributeCurrentValue, attributeMatchValue,
					ISharedImages.IMG_OBJS_CLASS);
		}
	}

}
